package com.fr.report.web.ui;

import com.fr.base.core.ComparatorUtils;
import com.fr.base.core.DateUtils;
import com.fr.base.core.json.JSONException;
import com.fr.base.core.json.JSONObject;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.web.Repository;
import java.text.DateFormat;
import java.util.Date;

public class DateEditor extends DirectWriteEditor
{
  private String startDate;
  private String endDate;
  private String formatText = "yyyy-MM-dd";
  private boolean returnDate = false;

  public String getXType()
  {
    return "datetime";
  }

  public String getFormatText()
  {
    return this.formatText;
  }

  public void setFormatText(String paramString)
  {
    this.formatText = paramString;
  }

  public String getStartDate()
  {
    return this.startDate;
  }

  public void setStartDate(String paramString)
  {
    this.startDate = paramString;
  }

  public String getEndDate()
  {
    return this.endDate;
  }

  public void setEndDate(String paramString)
  {
    this.endDate = paramString;
  }

  public boolean isReturnDate()
  {
    return this.returnDate;
  }

  public void setReturnDate(boolean paramBoolean)
  {
    this.returnDate = paramBoolean;
  }

  public JSONObject createJSONConfig(Object paramObject, Repository paramRepository)
    throws JSONException
  {
    JSONObject localJSONObject = super.createJSONConfig(paramObject, paramRepository);
    if (this.formatText != null)
      localJSONObject.put("format", this.formatText);
    if (this.startDate != null)
      localJSONObject.put("startDate", value2Config(this.startDate));
    if (this.endDate != null)
      localJSONObject.put("endDate", value2Config(this.endDate));
    if (this.returnDate)
      localJSONObject.put("returnDate", true);
    return localJSONObject;
  }

  protected Object value2Config(Object paramObject)
  {
    String str;
    if (paramObject instanceof Date)
      str = DateUtils.DATEFORMAT1.format((Date)paramObject);
    else
      str = (paramObject == null) ? "" : paramObject.toString();
    return str;
  }

  public String[] supportedEvents()
  {
    return new String[] { "afteredit" };
  }

  public boolean equals(Object paramObject)
  {
    return ((paramObject instanceof DateEditor) && (super.equals(paramObject)) && (ComparatorUtils.equals(this.startDate, ((DateEditor)paramObject).startDate)) && (ComparatorUtils.equals(this.endDate, ((DateEditor)paramObject).endDate)) && (this.returnDate == ((DateEditor)paramObject).returnDate));
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    super.readXML(paramXMLableReader);
    if (paramXMLableReader.isChildNode())
    {
      String str;
      if (paramXMLableReader.getTagName().equals("DateAttr"))
      {
        str = null;
        if ((str = paramXMLableReader.getAttr("format")) != null)
          setFormatText(str);
        if ((str = paramXMLableReader.getAttr("start")) != null)
          this.startDate = str;
        if ((str = paramXMLableReader.getAttr("end")) != null)
          this.endDate = str;
        if ((str = paramXMLableReader.getAttr("returnDate")) != null)
          this.returnDate = true;
      }
      if (paramXMLableReader.getTagName().equals("Attribute"))
      {
        str = null;
        if ((str = paramXMLableReader.getAttr("format")) != null)
          setFormatText(str);
      }
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    super.writeXML(paramXMLPrintWriter);
    paramXMLPrintWriter.startTAG("DateAttr");
    if (!(ComparatorUtils.equals(getFormatText(), "yyyy-MM-dd")))
      paramXMLPrintWriter.attr("format", getFormatText());
    if (this.startDate != null)
      paramXMLPrintWriter.attr("start", this.startDate);
    if (this.endDate != null)
      paramXMLPrintWriter.attr("end", this.endDate);
    if (this.returnDate)
      paramXMLPrintWriter.attr("returnDate", this.returnDate);
    paramXMLPrintWriter.end();
  }
}